home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 34
/
Amiga Format CD34 (1998-11-20)(Future Publishing)(GB)[!][Christmas issue].iso
/
-seriously_amiga-
/
programming
/
c
/
mesa-2.6
/
src-glu
/
mipmap.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-10-01
|
18KB
|
730 lines
/* $Id: mipmap.c,v 1.5 1997/07/24 01:28:44 brianp Exp $ */
/*
* Mesa 3-D graphics library
* Version: 2.4
* Copyright (C) 1995-1997 Brian Paul
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* mipmap.c
*
* Version 1.0 27 Jun 1998
* by Jarno van der Linden
* jarno@kcbbs.gen.nz
*
* File created from mipmap.c ver 1.5 and glu.h ver 1.9 using GenProtos
*
*/
#ifdef PC_HEADER
#include "all.h"
#else
#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "gluP.h"
#endif
/*
* Compute ceiling of integer quotient of A divided by B:
*/
#define CEILING( A, B ) ( (A) % (B) == 0 ? (A)/(B) : (A)/(B)+1 )
#ifdef EPSILON
#undef EPSILON
#endif
#define EPSILON 0.001
/* To work around optimizer bug in MSVC4.1 */
#ifdef __WIN32__
void dummy(GLuint j, GLuint k){
}
#else
#define dummy(J, K)
#endif
__asm __saveds GLint APIENTRY gluScaleImage( register __d0 GLenum format,
register __d1 GLint widthin, register __d2 GLint heightin,
register __d3 GLenum typein, register __a0 const void *datain,
register __d4 GLint widthout, register __d5 GLint heightout,
register __d6 GLenum typeout, register __a1 void *dataout )
{
GLint components, i, j, k;
GLfloat *tempin, *tempout;
GLfloat sx, sy;
GLint unpackrowlength, unpackalignment, unpackskiprows, unpackskippixels;
GLint packrowlength, packalignment, packskiprows, packskippixels;
GLint sizein, sizeout;
GLint rowstride, rowlen;
/* Determine number of components per pixel */
switch (format) {
case GL_COLOR_INDEX:
case GL_STENCIL_INDEX:
case GL_DEPTH_COMPONENT:
case GL_RED:
case GL_GREEN:
case GL_BLUE:
case GL_ALPHA:
case GL_LUMINANCE:
components = 1;
break;
case GL_LUMINANCE_ALPHA:
components = 2;
break;
case GL_RGB:
components = 3;
break;
case GL_RGBA:
components = 4;
break;
default:
return GLU_INVALID_ENUM;
}
/* Determine bytes per input datum */
switch (typein) {
case GL_UNSIGNED_BYTE: sizein = sizeof(GLubyte); break;
case GL_BYTE: sizein = sizeof(GLbyte); break;
case GL_UNSIGNED_SHORT: sizein = sizeof(GLushort); break;
case GL_SHORT: sizein = sizeof(GLshort); break;
case GL_UNSIGNED_INT: sizein = sizeof(GLuint); break;
case GL_INT: sizein = sizeof(GLint); break;
case GL_FLOAT: sizein = sizeof(GLfloat); break;
case GL_BITMAP:
/* not implemented yet */
default:
return GL_INVALID_ENUM;
}
/* Determine bytes per output datum */
switch (typeout) {
case GL_UNSIGNED_BYTE: sizeout = sizeof(GLubyte); break;
case GL_BYTE: sizeout = sizeof(GLbyte); break;
case GL_UNSIGNED_SHORT: sizeout = sizeof(GLushort); break;
case GL_SHORT: sizeout = sizeof(GLshort); break;
case GL_UNSIGNED_INT: sizeout = sizeof(GLuint); break;
case GL_INT: sizeout = sizeof(GLint); break;
case GL_FLOAT: sizeout = sizeof(GLfloat); break;
case GL_BITMAP:
/* not implemented yet */
default:
return GL_INVALID_ENUM;
}
/* Get glPixelStore state */
glGetIntegerv( GL_UNPACK_ROW_LENGTH, &unpackrowlength );
glGetIntegerv( GL_UNPACK_ALIGNMENT, &unpackalignment );
glGetIntegerv( GL_UNPACK_SKIP_ROWS, &unpackskiprows );
glGetIntegerv( GL_UNPACK_SKIP_PIXELS, &unpackskippixels );
glGetIntegerv( GL_PACK_ROW_LENGTH, &packrowlength );
glGetIntegerv( GL_PACK_ALIGNMENT, &packalignment );
glGetIntegerv( GL_PACK_SKIP_ROWS, &packskiprows );
glGetIntegerv( GL_PACK_SKIP_PIXELS, &packskippixels );
/* Allocate storage for intermediate images */
tempin = (GLfloat *) malloc( widthin * heightin
* components * sizeof(GLfloat) );
if (!tempin) {
return GLU_OUT_OF_MEMORY;
}
tempout = (GLfloat *) malloc( widthout * heightout
* components * sizeof(GLfloat) );
if (!tempout) {
free( tempin );
return GLU_OUT_OF_MEMORY;
}
/*
* Unpack the pixel data and convert to floating point
*/
if (unpackrowlength>0) {
rowlen = unpackrowlength;
}
else {
rowlen = widthin;
}
if (sizein >= unpackalignment) {
rowstride = components * rowlen;
}
else {
rowstride = unpackalignment/sizein
* CEILING( components * rowlen * sizein, unpackalignment );
}
switch (typein) {
case GL_UNSIGNED_BYTE:
k = 0;
for (i=0;i<heightin;i++) {
GLubyte *ubptr = (GLubyte *) datain
+ i * rowstride
+ unpackskiprows * rowstride
+ unpackskippixels * components;
for (j=0;j<widthin*components;j++) {
dummy(j, k);
tempin[k++] = (GLfloat) *ubptr++;
}
}
break;
case GL_BYTE:
k = 0;
for (i=0;i<heightin;i++) {
GLbyte *bptr = (GLbyte *) datain
+ i * rowstride
+ unpackskiprows * rowstride
+ unpackskippixels * components;
for (j=0;j<widthin*components;j++) {
dummy(j, k);
tempin[k++] = (GLfloat) *bptr++;
}
}
break;
case GL_UNSIGNED_SHORT:
k = 0;
for (i=0;i<heightin;i++) {
GLushort *usptr = (GLushort *) datain
+ i * rowstride
+ unpackskiprows * rowstride
+ unpackskippixels * components;
for (j=0;j<widthin*components;j++) {
dummy(j, k);
tempin[k++] = (GLfloat) *usptr++;
}
}
break;
case GL_SHORT:
k = 0;
for (i=0;i<heightin;i++) {
GLshort *sptr = (GLshort *) datain
+ i * rowstride
+ unpackskiprows * rowstride
+ unpackskippixels * components;
for (j=0;j<widthin*components;j++) {
dummy(j, k);
tempin[k++] = (GLfloat) *sptr++;
}
}
break;
case GL_UNSIGNED_INT:
k = 0;
for (i=0;i<heightin;i++) {
GLuint *uiptr = (GLuint *) datain
+ i * rowstride
+ unpackskiprows * rowstride
+ unpackskippixels * components;
for (j=0;j<widthin*components;j++) {
dummy(j, k);
tempin[k++] = (GLfloat) *uiptr++;
}
}
break;
case GL_INT:
k = 0;
for (i=0;i<heightin;i++) {
GLint *iptr = (GLint *) datain
+ i * rowstride
+ unpackskiprows * rowstride
+ unpackskippixels * components;
for (j=0;j<widthin*components;j++) {
dummy(j, k);
tempin[k++] = (GLfloat) *iptr++;
}
}
break;
case GL_FLOAT:
k = 0;
for (i=0;i<heightin;i++) {
GLfloat *fptr = (GLfloat *) datain
+ i * rowstride
+ unpackskiprows * rowstride
+ unpackskippixels * components;
for (j=0;j<widthin*components;j++) {
dummy(j, k);
tempin[k++] = *fptr++;
}
}
break;
default:
return GLU_INVALID_ENUM;
}
/*
* Scale the image!
*/
sx = (GLfloat) widthin / (GLfloat) widthout;
sy = (GLfloat) heightin / (GLfloat) heightout;
/*#define POINT_SAMPLE*/
#ifdef POINT_SAMPLE
for (i=0;i<heightout;i++) {
GLint ii = i * sy;
for (j=0;j<widthout;j++) {
GLint jj = j * sx;
GLfloat *src = tempin + (ii * widthin + jj) * components;
GLfloat *dst = tempout + (i * widthout + j) * components;
for (k=0;k<components;k++) {
*dst++ = *src++;
}
}
}
#else
if (sx<1.0 && sy<1.0) {
/* magnify both width and height: use